package com.acoreful.sample.commons.web.vo;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.CharUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.math.NumberUtils;

/**
 * 通常可用于Object[]向VO转换时
 * 提供了Object类型向常用数据类型的转换操作
 * 
 */
public abstract class BaseVo {
	
	public static String toString(Object obj) {
		return ObjectUtils.identityToString(obj);
	}
	
	public static Integer toInteger(Object obj) {
		return NumberUtils.toInt(toString(obj));
	}
	
	public static Long toLong(Object obj) {
		return NumberUtils.toLong(toString(obj));
	}
	
	public static Byte toByte(Object obj) {
		return NumberUtils.toByte(toString(obj));
	}
	
	public static Float toFloat(Object obj) {
		return NumberUtils.toFloat(toString(obj));
	}
	
	public static Double toDouble(Object obj) {
		return NumberUtils.toDouble(toString(obj));
	}
	
	public static Boolean toBoolean(Object obj) {
		return BooleanUtils.toBooleanObject(toString(obj));
	}
	
	public static Character toChar(Object obj) {
		return CharUtils.toCharacterObject(toString(obj));
	}
}